package msg

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

//请求成功
func Sucess(c *gin.Context, msg string, data ...interface{}) {
	if data != nil {
		c.JSON(http.StatusOK, gin.H{"code": 200, "msg": msg, "data": data[0]})
	} else {
		c.JSON(http.StatusOK, gin.H{"code": 200, "msg": msg, "data": data})
	}

	//responseBody := "{'code':200,'msg':" + msg + "," + fmt.Sprintf("'data':", data) + "}"
	//c.Set("response_body", responseBody)
	//tool.AddLogs(c)
	return
}

//请求失败
func Error(c *gin.Context, msg string) {
	c.JSON(http.StatusOK, gin.H{"code": 201, "msg": msg, "data": ""})
	//responseBody := "{'code':200,'msg':" + msg + "'data':null}"
	//c.Set("response_body", responseBody)
	//tool.AddLogs(c)
	return
}

//未登录
func NotLogin(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"code": 202, "msg": "未登录", "data": ""})
	//responseBody := "{'code':200,'msg':未登录}"
	//c.Set("response_body", responseBody)
	//tool.AddLogs(c)
	return
}
func NotAuthority(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"code": 203, "msg": "对不起，您无权操作", "data": ""})
	return
}
